#ifndef __PERFORMANCE_CONTROL_H__
#define __PERFORMANCE_CONTROL_H__

#include <windows.h>
#include <atlbase.h>
#include <atlstr.h>
#include <vector>
#include <string>

#include "DebugMonitor.h"

using namespace std;

typedef void (*CallbackFunc)(LPCSTR);
typedef struct _SMatchRecord
{
	_SMatchRecord(INT _pid, LPCSTR _msg, LARGE_INTEGER _t)
	{ pid = _pid; msg = _msg; timestamp = _t; }

	INT pid;
	string msg;
	LARGE_INTEGER timestamp;
} SMatchRecord;



class CPerformanceControl
{
public:
	CPerformanceControl();
	~CPerformanceControl();
	BOOL Init();
	int SetIniPath(LPCWSTR filepath);
	void PushMatchRecord(INT pid, LPCSTR msg);
	void SetMessageCallback(CallbackFunc func){m_msgCallback = func;};
	void CallbackLastRecord();
	static void _onMonitorCallback(INT pid, LPCSTR msg);

private:
	BOOL MatchFilterList(const string & str);
	BOOL LaunchProgram(LPCSTR szCurrentDir, BOOL bWaitFinish=FALSE);

private:
	CWinDebugMonitor* m_winDebugMonitor;
	
	CallbackFunc   m_msgCallback;
	LARGE_INTEGER  m_cpuFreq;
	LARGE_INTEGER  m_startClock;
	string         m_executeCmd;
	vector<string> m_filterList;
	vector<SMatchRecord> m_recordList;
	BOOL           m_notFilter;
};

#endif